package NGUYENVANTHANG.arrayt5;

public class Controllers {
	//Reversing Array
	public static void reversingArray(int[] array){
        int count = 0;
        int[] arr = new int[array.length];
        for(int i = array.length - 1; i >= 0; i--){
            arr[count] = array[i];
            count++;
        }       
    }
	
	//Bubble Sort
	public static void BubbleSort(int[] arr){
		for(int i=0;i<arr.length-1;i++){
		     for(int j=i+1;j<= arr.length-1;j++){
			  if(arr[i] > arr[j]){
			  	int temp = arr[i];
				arr[i] = arr[j];
				arr[j] = temp;
			          }
		     	}
		 }		
	}
	
	//Insertion Sort
	public static void insertionSort(double[] list) {
	      for (int i = 1; i < list.length; i++) {	       
	        double currentElement = list[i];
	        int k;
	        for (k = i - 1; k >= 0 && list[k] > currentElement; k--) {
	         list[k + 1] = list[k];
	       }	      
	       list[k + 1] = currentElement;
	     }	
	   }
	
	//Selection Sort
	public static void selectionSort(double[] list) {
	       for (int i = list.length - 1; i >= 1; i--){	        
	         double currentMax = list[0];
	         int currentMaxIndex = 0;
	         {for (int j = 1; j <= i; j++) {
	          if (currentMax < list[j]) {
	             currentMax = list[j];
	            currentMaxIndex = j;
	           }
	         } 
	         
	         if (currentMaxIndex != i) {
	           list[currentMaxIndex] = list[i];
	           list[i] = currentMax;
	         }
	       }
	    }
	  }
	}

